package lily.phs.object;

import lily.phs.database.Constants;
import android.content.ContentValues;
import android.content.Context;
import android.database.Cursor;
import android.net.Uri;


public class HospitalHistory implements Constants{
	
	private Context mContext;
	
	private int hohi_profileid=-1;
	private int hohi_testid=-1;
	private int hohi_id=-1;
	private String hohi_admit_date="";
	private String hohi_leave_date="";
	private String hohi_reason="";
	private String hohi_hospital="";
	private String hohi_number="";
	
	public HospitalHistory(Context context){
		this.mContext = context;
	}
	
	public int getHohi_profileid() {
		return hohi_profileid;
	}

	public void setHohi_profileid(int hohi_profileid) {
		this.hohi_profileid = hohi_profileid;
	}

	public int getHohi_testid() {
		return hohi_testid;
	}

	public void setHohi_testid(int hohi_testid) {
		this.hohi_testid = hohi_testid;
	}

	public int getHohi_id() {
		return hohi_id;
	}

	public void setHohi_id(int hohi_id) {
		this.hohi_id = hohi_id;
	}

	public String getHohi_admit_date() {
		return hohi_admit_date;
	}
	public void setHohi_admit_date(String hohi_admit_date) {
		this.hohi_admit_date = hohi_admit_date;
	}
	public String getHohi_leave_date() {
		return hohi_leave_date;
	}
	public void setHohi_leave_date(String hohi_leave_date) {
		this.hohi_leave_date = hohi_leave_date;
	}
	public String getHohi_reason() {
		return hohi_reason;
	}
	public void setHohi_reason(String hohi_reason) {
		this.hohi_reason = hohi_reason;
	}
	public String getHohi_hospital() {
		return hohi_hospital;
	}
	public void setHohi_hospital(String hohi_hospital) {
		this.hohi_hospital = hohi_hospital;
	}
	public String getHohi_number() {
		return hohi_number;
	}
	public void setHohi_number(String hohi_number) {
		this.hohi_number = hohi_number;
	}
	
	public void insertHospitalHistory(){
//		int result = -1;
		ContentValues value = new ContentValues();
		value.put(HOHI_COLUMN1, this.getHohi_profileid());
		value.put(HOHI_COLUMN7, this.getHohi_testid());
		value.put(HOHI_COLUMN8, this.getHohi_id());
		value.put(HOHI_COLUMN2, this.getHohi_admit_date());
		value.put(HOHI_COLUMN3, this.getHohi_leave_date());
		value.put(HOHI_COLUMN4, this.getHohi_reason());
		value.put(HOHI_COLUMN5, this.getHohi_hospital());
		value.put(HOHI_COLUMN6, this.getHohi_number());
		
//		Uri uri = 
		mContext.getContentResolver().insert(CONTENT_URI_TB6, value);
//		result = getIdFromUri(uri);
//		return result;
//		
	}
	
	/**
	 * 检出住院史信息，并实例化对象
	 * @param profileId 档案编号
	 * @param testId 体检表编号
	 * @param _Id 住院史编号
	 */
	public void selectHospitalHistory(int profileId,int testId,int _Id){
		String where = HOHI_COLUMN8 + "=" + _Id + " and "+HOHI_COLUMN1 + "=" + profileId + " and "+HOHI_COLUMN7 + "=" + testId + "";
		Cursor cursor = mContext.getContentResolver().query(CONTENT_URI_TB6, null, where, null, null);
		while(cursor.moveToNext()){
		this.hohi_profileid = cursor.getInt(cursor.getColumnIndex(HOHI_COLUMN1));
		this.hohi_testid = cursor.getInt(cursor.getColumnIndex(HOHI_COLUMN7));
		this.hohi_id = cursor.getInt(cursor.getColumnIndex(HOHI_COLUMN8));
		this.hohi_admit_date = cursor.getString(cursor.getColumnIndex(HOHI_COLUMN2));
		this.hohi_leave_date = cursor.getString(cursor.getColumnIndex(HOHI_COLUMN3));
		this.hohi_reason = cursor.getString(cursor.getColumnIndex(HOHI_COLUMN4));
		this.hohi_hospital = cursor.getString(cursor.getColumnIndex(HOHI_COLUMN5));
		this.hohi_number = cursor.getString(cursor.getColumnIndex(HOHI_COLUMN6));
		}
		cursor.close();
	}
	
	/**
	 * 修改住院史信息，并实例化对象
	 * @param profileId 档案编号
	 * @param testId 体检表编号
	 * @param _Id 住院史编号
	 */
	public void updateHospitalHistory(int profileId,int testId,int _Id){
		ContentValues value = new ContentValues();

		value.put(HOHI_COLUMN1, this.getHohi_profileid());
		value.put(HOHI_COLUMN7, this.getHohi_testid());
		value.put(HOHI_COLUMN8, this.getHohi_id());
		value.put(HOHI_COLUMN2, this.getHohi_admit_date());
		value.put(HOHI_COLUMN3, this.getHohi_leave_date());
		value.put(HOHI_COLUMN4, this.getHohi_reason());
		value.put(HOHI_COLUMN5, this.getHohi_hospital());
		value.put(HOHI_COLUMN6, this.getHohi_number());

		String where = HOHI_COLUMN8 + "=" + _Id + " and "+HOHI_COLUMN1 + "=" + profileId + " and "+HOHI_COLUMN7 + "=" + testId + "";
		mContext.getContentResolver().update(CONTENT_URI_TB6, value, where, null);
		
	}
	
	/**
	 * 删除患者的一次住院史信息
	 * @param profileId 档案编号
	 * @param testId 体检表编号
	 * @param _Id 住院史编号
	 */
	public void delectHospitalHistory(int profileId,int testId,int _Id){
		
		String where = HOHI_COLUMN8 + "=" + _Id + " and "+HOHI_COLUMN1 + "=" + profileId + " and "+HOHI_COLUMN7 + "=" + testId + "";
		mContext.getContentResolver().delete(CONTENT_URI_TB6, where, null);
		
	}
	
	/**
	 * 删除患者的全部住院史纪录
	 * @param profileId 档案编号
	 */
	public void delectHospitalHistory(int profileId){
		
		String where =  HOHI_COLUMN1 + "=" + profileId + "";
		mContext.getContentResolver().delete(CONTENT_URI_TB6, where, null);
		
	}

//	private int getIdFromUri(Uri uri) {
//		// TODO Auto-generated method stub
//		return 0;
//	}
}
